import React, {useMemo, useRef} from "react";
import { Space } from "antd";

import ProTable, { TableType, IProTableRef } from "vendor/components/pro-table";
import {useThemeToken} from "@/constants";

import { getDataAction, CreateOrEdit, Filter, MoreFilter } from './proTableDriver';
import { RespDataType } from '../api';
import { InitAdminBtn } from './btns';


const List: React.FC = () => {
    const { themeToken } = useThemeToken();
    const proTableRef = useRef<IProTableRef>();
    const columns = useMemo(() => getColumns(), []);

    return (
        <ProTable
            ref={proTableRef}
            dataAction={getDataAction(proTableRef)}
            rowKey={"id"}
            theme={themeToken.proTableToken}
            headerProps={{
                operatorProps: {
                    btnList: [
                        {innerType: "create"},
                        {innerType: "edit"},
                        {innerType: "delete"}
                    ],
                    createOrEditProps: {
                        modalProps:{
                            width: "40%"
                        },
                        // formatFormSchema:formatCreateOrEditSchema,
                        CreateOrEditContent: CreateOrEdit,
                        getModalTitle: (rowKey) => rowKey ? "编辑数据集" : "创建数据集",
                    },
                },
                filterProps:{
                    maxWidth: "60%",
                    FilterContent: Filter,
                    MoreFilterContent: MoreFilter,
                }
            }}
            contentProps={{
                tableProps: {
                    columns,
                }
            }}
            onError={(msg) => console.error(msg)}
        />
    )
}

export default List;

const getColumns = () => {

    const columns: TableType.ColumnsType<RespDataType.DataSetItem> = [
        {
            title: '名称',
            dataIndex: 'name',
        },
        {
            title: '创建人',
            dataIndex: 'createBy',
        },
        {
            title: '更新人',
            dataIndex: 'updateBy',
        },
        {
            title: '创建时间',
            dataIndex: 'createTime',
        },
        {
            title: "操作",
            render: () => <Space>
                <InitAdminBtn accountId="1" />
            </Space>
        }
    ];

    return columns;
}